# coding: iso-8859-15
# Author: Marc-Andre Belanger (centvingt@videotron.ca)
# Date: 14/09/2012
#
# This module includes the gibson related code. 

from panda3d.core import *
from . import BobEmitter, BobReceiver
import math, random

class GibsonBaseForkNode(NodePath):
    def __init__(self, aName):
        NodePath.__init__(self, aName)
        NodePath.setPythonTag(self, "subclass", self)
   

class GibsonBaseNode(NodePath):
	def __init__(self, gb, aName):
		NodePath.__init__(self, aName)
		NodePath.setPythonTag(self, "subclass", self)
		
		self.createRailReferenceNode()

		self.SEbaseNP = NodePath('SE base')
		self.SEbaseNP.reparentTo(self)
		
		cm = CardMaker('aGibsonNodeFace')
		cm.setColor(0.1, 0.1, 0.1, 0)
		
		#setFrame(ll, lr, ur, ul)
		cm.setFrame(Point3(-3,-3,0), Point3(-2.5,-3,0), Point3(-2.5,0,0), Point3(-3,0,0))
		self.SEbaseNP.attachNewNode(cm.generate())
		cm.setFrame(Point3(-2.5,-3,0), Point3(-1.5,-3,0), Point3(-1.5,-2.5,0), Point3(-2.5,-2.5,0))
		self.SEbaseNP.attachNewNode(cm.generate())
		cm.setFrame(Point3(-1.5,-3,0), Point3(0,-3,0), Point3(0,-1,0), Point3(-1.5,-1,0))
		self.SEbaseNP.attachNewNode(cm.generate())
		cm.setFrame(Point3(-2.5,-1.5,0), Point3(-1.5,-1.5,0), Point3(-1.5,0,0), Point3(-2.5,0,0))
		self.SEbaseNP.attachNewNode(cm.generate())
		cm.setFrame(Point3(-1.5,-1,0), Point3(-1,-1,0), Point3(-1,0,0), Point3(-1.5,0,0))
		self.SEbaseNP.attachNewNode(cm.generate())

		self.createRailSegment( -1.1, -0.1, 0.05, 1.8, 90)
		self.createRailSegment( -1.1, -0.1, 0, 1.8, 90)
		self.createRailTrans(-1.10, -0.1, 0, 0.05)
		self.createRailTrans(-1.28, -0.1, 0, 0.05)
		self.createRailTrans(-1.46, -0.1, 0, 0.05)
		self.createRailTrans(-1.64, -0.1, 0, 0.05)
		self.createRailTrans(-1.82, -0.1, 0, 0.05)
		self.createRailTrans(-2, -0.1, 0, 0.05)
		self.createRailTrans(-2.18, -0.1, 0, 0.05)
		self.createRailTrans(-2.36, -0.1, 0, 0.05)
		self.createRailTrans(-2.54, -0.1, 0, 0.05)
		self.createRailTrans(-2.72, -0.1, 0, 0.05)
		self.createRailTrans(-2.9, -0.1, 0, 0.05)
		
		self.createRailSegment( -1.1, -0.4, 0.05, 1, 90)
		self.createRailSegment( -1.1, -0.4, 0, 1, 90)
		self.createRailTrans(-1.10, -0.4, 0, 0.05)
		self.createRailTrans(-1.28, -0.4, 0, 0.05)
		self.createRailTrans(-1.46, -0.4, 0, 0.05)
		self.createRailTrans(-1.64, -0.4, 0, 0.05)
		self.createRailTrans(-1.82, -0.4, 0, 0.05)
		self.createRailTrans(-2, -0.4, 0, 0.05)
		self.createRailTrans(-2.1, -0.4, 0, 0.05)
		#
		self.createRailSegment( -2.1, -0.4, 0.05, 1.1, 180)
		self.createRailSegment( -2.1, -0.4, 0, 1.1, 180)
		self.createRailTrans(-2.1, -0.48, 0, 0.05)
		self.createRailTrans(-2.1, -0.66, 0, 0.05)
		self.createRailTrans(-2.1, -0.84, 0, 0.05)
		self.createRailTrans(-2.1, -1.02, 0, 0.05)
		self.createRailTrans(-2.1, -1.2, 0, 0.05)
		self.createRailTrans(-2.1, -1.38, 0, 0.05)
		self.createRailTrans(-2.1, -1.02, 0, 0.05)
		self.createRailTrans(-2.1, -1.5, 0, 0.05)
		# missing 0.06
		
		self.createRailSegment( -1.1, -0.6, 0.05, 0.8, 90)
		self.createRailSegment( -1.1, -0.6, 0, 0.8, 90)
		self.createRailTrans(-1.10, -0.6, 0, 0.05)
		self.createRailTrans(-1.28, -0.6, 0, 0.05)
		self.createRailTrans(-1.46, -0.6, 0, 0.05)
		self.createRailTrans(-1.64, -0.6, 0, 0.05)
		self.createRailTrans(-1.82, -0.6, 0, 0.05)
		self.createRailTrans(-1.9, -0.6, 0, 0.05)
		#
		
		self.createRailSegment( -1.9, -0.6, 0.05, 0.9, 180)
		self.createRailSegment( -1.9, -0.6, 0, 0.9, 180)
		self.createRailTrans(-1.9, -0.7, 0, 0.05)
		self.createRailTrans(-1.9, -0.88, 0, 0.05)
		self.createRailTrans(-1.9, -1.06, 0, 0.05)
		self.createRailTrans(-1.9, -1.24, 0, 0.05)
		self.createRailTrans(-1.9, -1.42, 0, 0.05)
		self.createRailTrans(-1.9, -1.5, 0, 0.05)
		# missing 0.1
		
		self.createRailSegment( -2.9, -0.1, 0.05, 1.8, 180)
		self.createRailSegment( -2.9, -0.1, 0, 1.8, 180)
		self.createRailTrans(-2.9, -0.28, 0, 0.05)
		self.createRailTrans(-2.9, -0.46, 0, 0.05)
		self.createRailTrans(-2.9, -0.64, 0, 0.05)
		self.createRailTrans(-2.9, -0.82, 0, 0.05)
		self.createRailTrans(-2.9, -1, 0, 0.05)
		self.createRailTrans(-2.9, -1.18, 0, 0.05)
		self.createRailTrans(-2.9, -1.36, 0, 0.05)
		self.createRailTrans(-2.9, -1.54, 0, 0.05)
		self.createRailTrans(-2.9, -1.72, 0, 0.05)
		self.createRailTrans(-2.9, -1.9, 0, 0.05)
		
		self.createRailSegment( -2.9, -1.9, 0.05, 0.4, 270)
		self.createRailSegment( -2.9, -1.9, 0, 0.4, 270)
		self.createRailTrans(-2.72, -1.9, 0, 0.05)
		self.createRailTrans(-2.54, -1.9, 0, 0.05)
		self.createRailTrans(-2.5, -1.9, 0, 0.05)
		#missing 0.14

		self.createRailSegment( -2.9, -2.1 ,0.05, 0.4, 270)
		self.createRailSegment( -2.9, -2.1, 0, 0.4, 270)
		self.createRailTrans(-2.9, -2.1, 0, 0.05)
		self.createRailTrans(-2.72, -2.1, 0, 0.05)
		#self.createRailTrans(-2.54, -2.1, 0, 0.05)
		self.createRailTrans(-2.5, -2.1, 0, 0.05)
		#missing 0.04

		self.createRailSegment( -2.9, -2.1 ,0.05, 0.8, 180)
		self.createRailSegment( -2.9, -2.1, 0, 0.8, 180)
		self.createRailTrans(-2.9, -2.28, 0, 0.05)
		self.createRailTrans(-2.9, -2.46, 0, 0.05)
		self.createRailTrans(-2.9, -2.64, 0, 0.05)
		self.createRailTrans(-2.9, -2.82, 0, 0.05)
		self.createRailTrans(-2.9, -2.9, 0, 0.05)
		# missing 0.1

		self.createRailSegment( -2.9, -2.9 ,0.05, 0.8, 270)
		self.createRailSegment( -2.9, -2.9, 0, 0.8, 270)
		self.createRailTrans(-2.8, -2.9, 0, 0.05)
		self.createRailTrans(-2.62, -2.9, 0, 0.05)
		self.createRailTrans(-2.44, -2.9, 0, 0.05)
		self.createRailTrans(-2.26, -2.9, 0, 0.05)
		self.createRailTrans(-2.1, -2.9, 0, 0.05)
		#missing 0.02
		self.createRailSegment( -2.1, -2.9 ,0.05, 0.4, 0)
		self.createRailSegment( -2.1, -2.9, 0, 0.4, 0)
		self.createRailTrans(-2.1, -2.7, 0, 0.05)
		self.createRailTrans(-2.1, -2.5, 0, 0.05)
		#missing 0.02
		
		self.createRailSegment( -0.6, -1.1, 0.05, 0.8, 180)
		self.createRailSegment( -0.6, -1.1, 0, 0.8, 180)
		self.createRailTrans(-0.6, -1.1, 0, 0.05)
		self.createRailTrans(-0.6, -1.28, 0, 0.05)
		self.createRailTrans(-0.6, -1.46, 0, 0.05)
		self.createRailTrans(-0.6, -1.64, 0, 0.05)
		self.createRailTrans(-0.6, -1.82, 0, 0.05)
		self.createRailTrans(-0.6, -1.9, 0, 0.05)
		# missing 0.1
		self.createRailSegment( -0.6, -1.9, 0.05, 0.9, 90)
		self.createRailSegment( -0.6, -1.9, 0, 0.9, 90)
		self.createRailTrans(-0.7, -1.9, 0, 0.05)
		self.createRailTrans(-0.88, -1.9, 0, 0.05)
		self.createRailTrans(-1.06, -1.9, 0, 0.05)
		self.createRailTrans(-1.24, -1.9, 0, 0.05)
		self.createRailTrans(-1.42, -1.9, 0, 0.05)
		self.createRailTrans(-1.5, -1.9, 0, 0.05)
		# missing 0.1

		self.createRailSegment( -0.4, -1.1, 0.05, 1, 180)
		self.createRailSegment( -0.4, -1.1, 0, 1, 180)
		self.createRailTrans(-0.4, -1.1, 0, 0.05)
		self.createRailTrans(-0.4, -1.28, 0, 0.05)
		self.createRailTrans(-0.4, -1.46, 0, 0.05)
		self.createRailTrans(-0.4, -1.64, 0, 0.05)
		self.createRailTrans(-0.4, -1.82, 0, 0.05)
		self.createRailTrans(-0.4, -2, 0, 0.05)
		self.createRailTrans(-0.4, -2.1, 0, 0.05)
		# missing 0.08
		
		self.createRailSegment( -0.4, -2.1, 0.05, 1.1, 90)
		self.createRailSegment( -0.4, -2.1, 0, 1.1, 90)
		self.createRailTrans(-0.58, -2.1, 0, 0.05)
		self.createRailTrans(-0.76, -2.1, 0, 0.05)
		self.createRailTrans(-0.94, -2.1, 0, 0.05)
		self.createRailTrans(-1.12, -2.1, 0, 0.05)
		self.createRailTrans(-1.3, -2.1, 0, 0.05)
		self.createRailTrans(-1.42, -2.1, 0, 0.05)
		self.createRailTrans(-1.5, -2.1, 0, 0.05)
		# missing 0.1

		self.createRailSegment( -0.1, -2.9 ,0.05, 1.8, 90)
		self.createRailSegment( -0.1, -2.9, 0, 1.8, 90)
		self.createRailTrans(-0.28, -2.9, 0, 0.05)
		self.createRailTrans(-0.46, -2.9, 0, 0.05)
		self.createRailTrans(-0.28, -2.9, 0, 0.05)
		self.createRailTrans(-0.64, -2.9, 0, 0.05)
		self.createRailTrans(-0.82, -2.9, 0, 0.05)
		self.createRailTrans(-1, -2.9, 0, 0.05)
		self.createRailTrans(-1.18, -2.9, 0, 0.05)
		self.createRailTrans(-1.36, -2.9, 0, 0.05)
		self.createRailTrans(-1.54, -2.9, 0, 0.05)
		self.createRailTrans(-1.72, -2.9, 0, 0.05)
		self.createRailTrans(-1.9, -2.9, 0, 0.05)

		self.createRailSegment( -1.9, -2.9 ,0.05, 0.4, 0)
		self.createRailSegment( -1.9, -2.9, 0, 0.4, 0)
		self.createRailTrans(-1.9, -2.72, 0, 0.05)
		self.createRailTrans(-1.9, -2.54, 0, 0.05)
		self.createRailTrans(-1.9, -2.5, 0, 0.05)
		
		self.createRailSegment( -0.1, -1.1 ,0.05, 1.8, 180)
		self.createRailSegment( -0.1, -1.1, 0, 1.8, 180)
		self.createRailTrans(-0.1, -1.1, 0, 0.05)
		self.createRailTrans(-0.1, -1.28, 0, 0.05)
		self.createRailTrans(-0.1, -1.46, 0, 0.05)
		self.createRailTrans(-0.1, -1.64, 0, 0.05)
		self.createRailTrans(-0.1, -1.28, 0, 0.05)
		self.createRailTrans(-0.1, -1.82, 0, 0.05)
		self.createRailTrans(-0.1, -2, 0, 0.05)
		self.createRailTrans(-0.1, -2.18, 0, 0.05)
		self.createRailTrans(-0.1, -2.36, 0, 0.05)
		self.createRailTrans(-0.1, -2.54, 0, 0.05)
		self.createRailTrans(-0.1, -2.72, 0, 0.05)
		self.createRailTrans(-0.1, -2.9, 0, 0.05)
		
		self.SEbaseNP.flattenStrong()
		
		SWbaseNodePath = NodePath('SW base')
		self.SEbaseNP.copyTo(SWbaseNodePath)
		SWbaseNodePath.setHpr(90, 0, 0)
		SWbaseNodePath.reparentTo(self)

		NWbaseNodePath = NodePath('NW base')
		self.SEbaseNP.copyTo(NWbaseNodePath)
		NWbaseNodePath.setHpr(180, 0, 0)
		NWbaseNodePath.reparentTo(self)

		NEbaseNodePath = NodePath('NE base')
		self.SEbaseNP.copyTo(NEbaseNodePath)
		NEbaseNodePath.setHpr(270, 0, 0)
		NEbaseNodePath.reparentTo(self)

		
		SWfork = GibsonBaseForkNode(aName + 'swfork')
		SWfork.setPos(-2, -2, 0)
		SWfork.reparentTo(self)
		SEfork = GibsonBaseForkNode(aName + 'sefork')
		SEfork.setPos(2, -2, 0)
		SEfork.reparentTo(self)
		NWfork = GibsonBaseForkNode(aName + 'nwfork')
		NWfork.setPos(2, 2, 0)
		NWfork.reparentTo(self)
		NEfork = GibsonBaseForkNode(aName + 'nefork')
		NEfork.setPos(-2, 2, 0)
		NEfork.reparentTo(self)
		
		#gb = self.getAncestor(1)
		gb.bobReceiverArray.append( BobReceiver(gb, -0.5, 1.1, NWfork) )
		gb.bobReceiverArray.append( BobReceiver(gb, 0.5, 1.1, NEfork) )
		gb.bobReceiverArray.append( BobReceiver(gb, -0.5, -1.1, SWfork) )
		gb.bobReceiverArray.append( BobReceiver(gb, 0.5, -1.1, SEfork) )
		gb.bobReceiverArray.append( BobReceiver(gb, 1.1, -0.5, SEfork) )
		gb.bobReceiverArray.append( BobReceiver(gb, 1.1, 0.5, NEfork) )
		gb.bobReceiverArray.append( BobReceiver(gb, -1.1, -0.5, SWfork) )
		gb.bobReceiverArray.append( BobReceiver(gb, -1.1, 0.5, SEfork) )

		self.createLights(-1, -1, 0.6)
		self.createLights(-1, 1, 0.6)
		self.createLights(1, -1, 0.6)
		self.createLights(1, 1, 0.6)

	def createLights(self, x, y, z):
		light = PointLight('a light')
		light.setColor(VBase4(0.1, 0.4, 0.1, 0))	
		lightNP = self.attachNewNode(light)
		lightNP.setPos(x, y, z)
		self.setLight(lightNP)
	
		
	#t3 = NodePath('pointer')
		#t3.setPos(-3, -0.025, 0.025)
		#t3.reparentTo(self)
		#t2.lookAt(t3)
		
	def createRailSegment(self, x, y, z, len, rotx):
		t = NodePath(self.pentaReference.makeCopy())
		t.setScale(0.005, len, 0.005)
		t.setHpr(rotx,0,0)
		t.setPos(x,y,z)
		t.reparentTo(self.SEbaseNP)
		
	def createRailTrans(self, x, y, z, len):
		t = NodePath(self.pentaReference.makeCopy())
		t.setScale(0.005, len, 0.005)
		t.setHpr(0,90,0)
		t.setPos(x,y,z)
		t.reparentTo(self.SEbaseNP)
		
	def createRailReferenceNode(self):
		format=GeomVertexFormat.getV3c4()
		vdata=GeomVertexData('PentaTube', format, Geom.UHDynamic)
		
		vertex=GeomVertexWriter(vdata, 'vertex')
		#normal=GeomVertexWriter(vdata, 'normal')
		color=GeomVertexWriter(vdata, 'color')
		#texcoord=GeomVertexWriter(vdata, 'texcoord')
		cr = 0.8
		cg = 0.8
		cb = 0.8
		ca = 0.3
		
		c1 = math.cos((math.pi*2)/5)
		c2 = math.cos(math.pi/5)
		s1 = math.sin((math.pi*2)/5)
		s2 = math.sin((math.pi*4)/5)
		# v = x, y, z
		vertex.addData3f(0, 0, 0)
		color.addData4f(cr,cg,cb,ca)
		vertex.addData3f(0, 0, 1)
		color.addData4f(cr,cg,cb,ca)
		vertex.addData3f(0 - s1, 0, c1)
		color.addData4f(cr,cg,cb,ca)
		vertex.addData3f(0 - s2, 0, 0 - c2)
		color.addData4f(cr,cg,cb,ca)
		vertex.addData3f(s2, 0, 0 - c2)
		color.addData4f(cr,cg,cb,ca)
		vertex.addData3f(s1, 0, c1)
		color.addData4f(cr,cg,cb,ca)

		vertex.addData3f(0, 1, 1)
		color.addData4f(cr,cg,cb,ca)
		vertex.addData3f(0 - s1, 1, c1)
		color.addData4f(cr,cg,cb,ca)
		vertex.addData3f(0 - s2, 1, 0 - c2)
		color.addData4f(cr,cg,cb,ca)
		vertex.addData3f(s2, 1, 0 - c2)
		color.addData4f(cr,cg,cb,ca)
		vertex.addData3f(s1, 1, c1)
		color.addData4f(cr,cg,cb,ca)
		vertex.addData3f(0, 1, 0)
		color.addData4f(cr,cg,cb,ca)

		penta=Geom(vdata)
		
		self.model(penta, GeomTriangles(Geom.UHDynamic), 0, 1, 2)
		self.model(penta, GeomTriangles(Geom.UHDynamic), 0, 2, 3)
		self.model(penta, GeomTriangles(Geom.UHDynamic), 0, 3, 4)
		self.model(penta, GeomTriangles(Geom.UHDynamic), 0, 4, 5)
		self.model(penta, GeomTriangles(Geom.UHDynamic), 0, 5, 1)
		
		self.model(penta, GeomTriangles(Geom.UHDynamic), 1, 6, 2)
		self.model(penta, GeomTriangles(Geom.UHDynamic), 1, 5, 6)
		self.model(penta, GeomTriangles(Geom.UHDynamic), 2, 6, 7)
		self.model(penta, GeomTriangles(Geom.UHDynamic), 2, 7, 8)
		self.model(penta, GeomTriangles(Geom.UHDynamic), 3, 2, 8)
		self.model(penta, GeomTriangles(Geom.UHDynamic), 3, 8, 9)
		self.model(penta, GeomTriangles(Geom.UHDynamic), 4, 3, 9)
		self.model(penta, GeomTriangles(Geom.UHDynamic), 5, 4, 9)
		self.model(penta, GeomTriangles(Geom.UHDynamic), 5, 9, 10)
		self.model(penta, GeomTriangles(Geom.UHDynamic), 5, 10, 6)

		self.model(penta, GeomTriangles(Geom.UHDynamic), 11, 10, 9)
		self.model(penta, GeomTriangles(Geom.UHDynamic), 11, 9, 8)
		self.model(penta, GeomTriangles(Geom.UHDynamic), 11, 8, 7)
		self.model(penta, GeomTriangles(Geom.UHDynamic), 11, 7, 6)
		self.model(penta, GeomTriangles(Geom.UHDynamic), 11, 6, 10)
		
		
		self.pentaReference=GeomNode('penta')
		self.pentaReference.addGeom(penta)

		#self.pentaReference.attachNewNode(snode)
		#self.pentaNode.setScale(1, 10, 1)
		#self.pentaNode.hprInterval(30,Point3(360,0,0)).loop()
		#render.setRenderModeWireframe()
		
	def model(self,	penta, tri, v1, v2, v3):
		#tri=GeomTriangles(Geom.UHDynamic)
		tri.addVertices(v1, v2, v3)
		tri.closePrimitive()
		penta.addPrimitive(tri)
	

		
class GibsonNode(NodePath):
	texturefactory = ''
	bobEmitterArray = []
	bobReceiverArray = []
	
	def __init__(self, aName, tf):
		NodePath.__init__(self, aName)
		NodePath.setPythonTag(self, "subclass", self)
		
		self.texturefactory = tf
		self.__createGibsonStructure()

		# Emitter creation left to Gibson Node...
		self.__createBobEmitterArray()

		# Receiver creation transfered to the GibsonBaseNode
		#self.__createBobReceiverArray()
		self.__createGibsonBase()
	
	def __createGibsonBase(self):
		#create gibson base
		#self.baseNode = loader.loadModel(Filename("models/gibson base"))
		#self.baseNode.setScale(1)
		#self.baseNode.setCollideMask(BitMask32.allOn())
		#self.baseNode.reparentTo(self)

		self.baseNP = GibsonBaseNode(self, 'a base')
		self.baseNP.reparentTo(self)
	
		
	def __createBobEmitterArray(self):
		self.bobEmitterArray.append( BobEmitter(self, 0, 1.1) )
		self.bobEmitterArray.append( BobEmitter(self, 0, -1.1) )
		self.bobEmitterArray.append( BobEmitter(self, 1.1, 0) )
		self.bobEmitterArray.append( BobEmitter(self, -1.1, 0) )
	
	def __createBobReceiverArray(self):
		self.bobReceiverArray.append( BobReceiver(self, -0.5, 1.1) )
		self.bobReceiverArray.append( BobReceiver(self, 0.5, 1.1) )
		self.bobReceiverArray.append( BobReceiver(self, -0.5, -1.1) )
		self.bobReceiverArray.append( BobReceiver(self, 0.5, -1.1) )
		self.bobReceiverArray.append( BobReceiver(self, 1.1, -0.5) )
		self.bobReceiverArray.append( BobReceiver(self, 1.1, 0.5) )
		self.bobReceiverArray.append( BobReceiver(self, -1.1, -0.5) )
		self.bobReceiverArray.append( BobReceiver(self, -1.1, 0.5) )
	
	def getRandomEmitter(self):
		return random.choice(self.bobEmitterArray)
		
	def getRandomReceiver(self):
		return random.choice(self.bobReceiverArray)
		
	def __createGibsonStructure(self):

		cm = CardMaker('aGibsonNodeFace')
		#setFrame(ll, lr, ur, ul)
		cm.setFrame(Point3(-1,-1,0), Point3(1,-1,0), Point3(1,-1,6), Point3(-1,-1,6))
		cm.setHasUvs(1)
		facetexture = self.texturefactory.getRandomTexture().textTexture
		self.__face = self.attachNewNode(cm.generate())
		self.__face.setTransparency(1)
		self.__face.setTexture(facetexture)
		self.__face.setTwoSided(1)
		#self.__facewf = self.attachNewNode(cm.generate())
		#self.__facewf.setRenderModeWireframe()
				
		cmback = CardMaker('aGibsonBack')
		cmback.setFrame(Point3(1,1,0), Point3(-1,1,0), Point3(-1,1,6), Point3(1,1,6))
		cm.setHasUvs(1)
		backtexture = self.texturefactory.getRandomTexture().textTexture
		self.__back = self.attachNewNode(cmback.generate())
		self.__back.setTwoSided(1)
		#self.__back.setAttrib(CullFaceAttrib.make(CullFaceAttrib.MCullCounterClockwise))
		self.__back.setTransparency(1)
		self.__back.setTexture(backtexture)
		
		cmright = CardMaker('aGibsonRight')
		cmright.setFrame(Point3(1,-1,0), Point3(1,1,0), Point3(1,1,6), Point3(1,-1,6))
		cmright.setHasUvs(1)
		righttexture = self.texturefactory.getRandomTexture().textTexture
		self.__right = self.attachNewNode(cmright.generate())
		self.__right.setTwoSided(1)
		#self.__right.setAttrib(CullFaceAttrib.make(CullFaceAttrib.MCullCounterClockwise))
		self.__right.setTransparency(1)
		self.__right.setTexture(righttexture)

		cmleft = CardMaker('aGibsonLeft')
		cmleft.setFrame(Point3(-1,1,0), Point3(-1,-1,0), Point3(-1,-1,6), Point3(-1,1,6))
		cmleft.setHasUvs(1)
		lefttexture = self.texturefactory.getRandomTexture().textTexture
		self.__left = self.attachNewNode(cmleft.generate())
		self.__left.setTwoSided(1)
		#self.__right.setAttrib(CullFaceAttrib.make(CullFaceAttrib.MCullCounterClockwise))
		self.__left.setTransparency(1)
		self.__left.setTexture(lefttexture)
		
		#num = random.randint(0, len(self.texturefactory.textureArray)-1)
		#self.__face.setTexture(self.texturefactory.textureArray[num])
		#self.__face.setTexScale(TextureStage.getDefault(), TexGenAttrib.MWorldPosition)
